from gameset.phoenicia.base import *


class SeaResource(Good):
    likelyhood =_ (None)


class Fish(SeaResource, Food):
    singular   =_ ('Fish')
    plural     =_ ('Fish')
    happiness  =_ (1.0)
    consumed   =_ (1)
    likelyhood =_ (1)


class Fisher(Seeker):
    color    =_ (Blue.with_value(0.2))
    speed    =_ (5)
    radius   =_ (5)
    capacity =_ (20)
    
    def on_idle(self):
        if not self.tile.is_next_to_water or self.one_in(250):
            self.move_around()
    
    def move_around(self):
        position = self.home.position.random_nearby(self.radius)
        tile     = self.city.map.at(position)
        
        if tile.is_passable and tile.is_next_to_water:
            self.move_to(position)
    
    def day(self, day, month, year):
        if self.tile.is_next_to_water:
            for type in SeaResource.all_concrete_subtypes:
                if self.one_in(type.likelyhood):
                    self.create(type(1))
        
        if self.storage.is_full:
            self.move_home()
    
    def on_arrival_home(self):
        self.unload_into(self.home)
        self.destroy()


class Fishery(StaffedBuilding):
    name       =_ ('Fishery')
    color      =_ (Blue.with_value(0.2))
    profession =_ (Fisher)
    cost       =_ (50)
    staff      =_ (6)
    agents     =_ (3)
    size       =_ (2)
    stores     =_ (SeaResource(400))
    supply     =_ ([SeaResource])
    
    @property
    def spawn_point(self):
        return self.access_point
